package com.shbaiche.bifenba.adapter.my;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shbaiche.bifenba.App;
import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.kit.AppKit;
import com.shbaiche.bifenba.model.base.BoolValue;
import com.shbaiche.bifenba.model.base.TransMessage;
import com.shbaiche.bifenba.model.user.FollowInfoVo;
import com.shbaiche.bifenba.model.video.ArticleDiscussVo;
import com.shbaiche.bifenba.model.video.DiscussFollowMessage;
import com.shbaiche.bifenba.net.JsonCallback;
import com.shbaiche.bifenba.net.NetApi;
import com.shbaiche.bifenba.ui.my.LoginActivity;
import com.shbaiche.bifenba.util.ToastUtil;
import com.shbaiche.bifenba.view.CircularImage;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;

public class MoreFollowAdapter extends BaseAdapter {
    private Context context;

    public List<FollowInfoVo> his;

    public Map<Integer, BoolValue> isFollowMap;

    public int index = 0;

    public MoreFollowAdapter(Context context) {
        super();
        this.context = context;
    }

    public void setData(List<FollowInfoVo> data) {

        this.his = data;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        if (his == null)
            return 0;
        return his.size();
    }


    @Override
    public FollowInfoVo getItem(int arg0) {
        return his.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(final int position, View v, ViewGroup arg2) {
        ViewHolder holder = null;
        if (v == null) {
            holder = new ViewHolder();
            v = LayoutInflater.from(context).inflate(R.layout.adapter_more_list, null);
            holder.name = (TextView) v.findViewById(R.id.more_name);
            holder.click = (ImageView) v.findViewById(R.id.more_click);
            holder.head = (CircularImage) v.findViewById(R.id.more_logo);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();

        }
        final FollowInfoVo item = getItem(position);

        Glide.with(context).load(item.getLogo()).placeholder(R.drawable.ic_my_head).error(R.drawable.ic_my_head).into(holder.head);

        holder.name.setText(item.getName() + "");

        if (isFollowMap.get(position).getValue()) {
            holder.click.setImageResource(R.drawable.btn_xuan_press);
        } else {
            holder.click.setImageResource(R.drawable.btn_xuan_normall);
        }


        if (v != null) {
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (isFollowMap.get(position).getValue()) {
                        isFollowMap.put(position, BoolValue.NO);
                    } else {
                        isFollowMap.put(position, BoolValue.YES);
                    }
                    notifyDataSetChanged();
                }
            });
        }

        return v;
    }

    class ViewHolder {
        CircularImage head;
        TextView name;
        ImageView click;
    }
}
